package com.ler.yrmall.product.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ler.yrmall.product.entity.SpuImagesEntity;
import com.ler.yrmall.product.service.SpuImagesService;
import com.ler.yrmall.basic.Result;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;


/**
 * spuImage
 * @author Leron
 */
@RestController
@RequestMapping("/spuImages")
public class SpuImagesController {

    @Resource
    private SpuImagesService spuImagesService;

    @RequestMapping("/list/{spuId}")
    public Result<?> list(@PathVariable Long spuId) {
        List<SpuImagesEntity> list = spuImagesService.list(Wrappers.<SpuImagesEntity>lambdaQuery().eq(SpuImagesEntity::getSpuId, spuId));
        return Result.ok((list));
    }


    /**
     * 保存
     */
    @RequestMapping("/save")
    public Result<?> save(@RequestBody SpuImagesEntity spuImages) {
        spuImagesService.save(spuImages);
        return Result.ok();
    }


    /**
     * 删除
     */
    @RequestMapping("/delete")
    public Result<?> delete(@RequestBody Long[] ids) {
        spuImagesService.removeByIds(Arrays.asList(ids));
        return Result.ok();
    }

}
